home *** CD-ROM | disk | FTP | other *** search
/ Software Vault: The Gold Collection / Software Vault - The Gold Collection (American Databankers) (1993).ISO / cdr49 / 273_01.zip / CALCTOT.CC < prev    next >
Text File  |  1993-04-04  |  1KB  |  55 lines

  1. #include <dos.h>
  2. #include <dir.h>
  3. #include <string.h>
  4.  
  5.  
  6.  
  7. long calc_tots(char *curr_path)
  8. /* This function will accept a valid path name I.E. c:\dos and will return
  9.    the total number of bytes occupied by all files in the specified directory.
  10. */
  11. {
  12. long path_tot = 0;
  13. int rc;
  14. char *next_search, *next_path;
  15. struct ffblk *new_dta;
  16. int x;
  17.     next_search=(char *)malloc(80);
  18.     next_path=(char *)malloc(80);
  19.     new_dta=(struct ffblk *)malloc(sizeof(struct ffblk));
  20.     x=strlen(curr_path) - 1;
  21.     if(*(curr_path + x) == '\\')
  22.         *(curr_path + x) = 0x00;
  23.     strcpy(next_search,curr_path);
  24.     strcat(next_search,"\\*.*");
  25.     rc=findfirst(next_search,new_dta,0xff);
  26.     if(rc) goto fin_up;
  27.     if(new_dta->ff_attrib & FA_LABEL) goto do_next;
  28.     if(new_dta->ff_name[0] == '.') goto do_next;
  29.     if(new_dta->ff_attrib & FA_DIREC) {
  30.         strcpy(next_path,curr_path);
  31.         strcat(next_path,"\\");
  32.         strcat(next_path,new_dta->ff_name);
  33.         path_tot += calc_tots(next_path);
  34.     }
  35.     path_tot = path_tot + new_dta->ff_fsize;
  36. do_next:
  37.     rc=findnext(new_dta);    
  38.     if(rc) goto fin_up;
  39.     if(new_dta->ff_attrib & FA_LABEL) goto do_next;
  40.     if(new_dta->ff_name[0] == '.') goto do_next;
  41.     if(new_dta->ff_attrib & FA_DIREC) {
  42.         strcpy(next_path,curr_path);
  43.         strcat(next_path,"\\");
  44.         strcat(next_path,new_dta->ff_name);
  45.         path_tot += calc_tots(next_path);
  46.     }
  47.     path_tot = path_tot + new_dta->ff_fsize;
  48.     goto do_next;
  49. fin_up:
  50.     free(next_search);
  51.     free(next_path);
  52.     free(new_dta);    
  53.     return(path_tot);
  54. }
  55.